#include("../common/header.html")
<body>
	<div id="container" style="background-color:#F4F4F4;">
		
	</div>
</body>
<script>
	$(document)[0].title="我的订单";
 	$(document).ready(function (){
		var page=1;
		var html='';
		var length=[];
		$.ajax({
			type: "GET",
			url: "#(ctx)/wap/order/list",
			data:{'act':'ajaxpage','page':page},
			dataType: "json",
			success: function(data){
				if(data.length>0){
					$("#container").html('');
					$.each(data, function(idx, obj) {
						html = `
						<div class="orderlist">
							<div class="orderitem flex">
								<div class="orderL">
									<img class="orderimg" src="`+obj.thumb+`"></img>	
								</div>
								<div class="orderDetail">
									<div class="orderModel between">
										<div>`+obj.title+`</div>
										`;
										if(obj.type==1&&obj.status==1){
											html+="<div>待发货</div>"
										}else if(obj.type==1&&obj.status==2){
											html+="<div>已发货</div>"
										}else{
											html+="<div>未中奖</div>"
										}
										html+=
									`</div>
									<div class="orderName">`+obj.model+`</div>
									<div class="orderStatus">
									`;
										if(obj.type!=1){
											html+=`挑战失败`
										}else{
											html+=`挑战成功 免费包邮`
										}
										html+=`
									</div>

								</div>		
							</div>
							<div class="ordernum">
								<div>订单编号：`+obj.trade_no+`</div>	
							</div>
						</div>
						`;
						
						$("#container").append(html);
					});
					page++;
				}
				for (var i in data) {
					length.push(data[i])
				}

				if(length.length==0){
						$("#container").append('<p style="margin-top:5vw;text-align:center">暂无数据</p>');
				}
			}
		});

        var nScrollHight = 0; //滚动距离总长(注意不是滚动条的长度)
        var nScrollTop = 0;   //滚动到的当前位置
        var nDivHight = $("#container").height();
        
        $("#container").scroll(function(){
        	nScrollHight = $(this)[0].scrollHeight;
        	nScrollTop = $(this)[0].scrollTop;
        	if(nScrollTop + nDivHight >= nScrollHight){
        		// alert("滚动条到底部了");
        		console.log("到底了");

        		$.ajax({
					type: "GET",
					url: "#(ctx)/wap/order/list",
					data:{'act':'ajaxpage','page':page},
					dataType: "json",
					success: function(data){
						if(data.length>0){
        					$.each(data, function(idx, obj) {
						html = `
						<div class="orderlist">
							<div class="orderitem flex">
								<div class="orderL">
									<img class="orderimg" src="`+obj.thumb+`"></img>	
								</div>
								<div class="orderDetail">
									<div class="orderModel between">
										<div>`+obj.title+`</div>
										`
										if(obj.type==1&&obj.status==1){
											html+="<div>待发货</div>"
										}else if(obj.type==1&&obj.status==2){
											html+="<div>已发货</div>"
										}else{
											html+="<div>未中奖</div>"
										}
										html+=
									`</div>
									<div class="orderName">`+obj.model+`</div>
									<div class="orderStatus">
									`
										if(obj.type!=1){
											html+=`挑战失败`
										}else{
											html+=`挑战成功 免费包邮`
										}
										html+=`
									</div>

								</div>		
							</div>
							<div class="ordernum">
								<div>订单编号：`+obj.trade_no+`</div>	
							</div>
						</div>
						`;
						
						$("#container").append(html);
							});
							page++;
						}
					}
				});
        	}

        });
    });
</script>
</html>